<?php
/**
 * 消息类
 * User: angl
 * Date: 16/2/3
 * Time: 下午4:32
 */

require_once (API_ROOT_PATH . '/../inc/Config.php');
require_once (API_ROOT_PATH . '/../inc/MysqliDb.php');

$db = new MysqliDb(MYSQLDB, MYSQLDB_USER, MYSQLDB_PWD, MYSQLDB_DATABASE);

/**
 * 发送消息接口
 * @param int $uid 用户ID
 * @param String $title 消息标题
 * @param String $content
 * @param int $from
 * @param int $type
 * @return int 消息id
 */
function sendMessage($uid, $title, $content, $from = 0, $type = 1)
{
    global $db;
    if ((int)$uid < 1 || empty($title) || empty($content)) {
        return false;
    }
    $data = array(
        'uid' => $uid,
        'title' => $title,
        'content' => $content,
        'from' => $from,
        'type' => $type,
        'is_read' => 0,
        'create_time' => date("Y-m-d H:i:s")
    );
    return $db->insert("au_inbox", $data);
}